//
//  ViewController.m
//  04-QQHomeWork
//
//  Created by 曹曹 on 16/7/19.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
#import "GX_Button.h"

#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width

@interface ViewController ()
@property (nonatomic, strong) UIImageView *backgroundView;
@property (nonatomic, strong) AVAudioPlayer *player;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self backgroundImageView];
    [self downpullButton];
    [self upImageView];
    [self topLabel];
    [self topLines];
    [self songImageView];
    [self pageControl];
    [self slider];
    [self playButton];
    [self timeLabel];
    [self bottomItem];
}
#pragma mark - 背景
- (void)backgroundImageView {
    _backgroundView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    _backgroundView.image = [UIImage imageNamed:@"profile_homepage_default_bg"];
    _backgroundView.alpha = 0.8;
    [self.view addSubview:_backgroundView];
}
#pragma mark - 下拉按钮
- (void)downpullButton {
    GX_Button *downpullButton = [GX_Button buttonWithType:UIButtonTypeSystem];
    downpullButton.frame = CGRectMake(20, 40, 40, 40);
    [downpullButton setImage:[UIImage imageNamed:@"miniplayer_btn_playlist_close"] forState:UIControlStateNormal];
    downpullButton.tintColor = [UIColor whiteColor];
    [self.view addSubview:downpullButton];
}
#pragma mark - 标准,独家,MV,dts
- (void)upImageView {
    for (int i = 0; i < 4; i++) {
        GX_Button *button = [GX_Button buttonWithType:UIButtonTypeSystem];
        button.frame = CGRectMake(55 + i * ((SCREEN_WIDTH - 140) / 4 + 10), 130, (SCREEN_WIDTH - 140) / 4, 25);
        [button setImage:[[UIImage imageNamed:[NSString stringWithFormat:@"top%d", i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        [self.view addSubview:button];
    }
}
#pragma mark - 歌曲和作者
- (void)topLabel {
    UILabel *songLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 80, 40)];
    songLabel.text = @"稻香";
    songLabel.textAlignment = NSTextAlignmentCenter;
    songLabel.textColor = [UIColor whiteColor];
    songLabel.font = [UIFont systemFontOfSize:30];
    songLabel.center = CGPointMake(SCREEN_WIDTH / 2, 60);
    UILabel *authorLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 300, 60, 40)];
    authorLabel.text = @"周杰伦";
    authorLabel.textAlignment = NSTextAlignmentCenter;
    authorLabel.textColor = [UIColor whiteColor];
    authorLabel.center = CGPointMake(SCREEN_WIDTH / 2, 100);
    [self.view addSubview:songLabel];
    [self.view addSubview:authorLabel];
}
#pragma mark - 细线
- (void)topLines {
    UIView *viewOfLineLeft = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 - 80, 60, 30, 1)];
    UIView *viewOfLineRigt = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 + 50, 60, 30, 1)];
    viewOfLineLeft.backgroundColor = [UIColor whiteColor];
    viewOfLineRigt.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:viewOfLineLeft];
    [self.view addSubview:viewOfLineRigt];
}
#pragma mark - 中间图片
- (void)songImageView {
    UIImageView *backView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
    backView.image = [UIImage imageNamed:@"player_icon_mvPreview"];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"songImage"]];
    imageView.frame = CGRectMake(SCREEN_WIDTH / 2 - 140, 180, 280, 280);
    backView.center = imageView.center;
    backView.layer.cornerRadius = 150;
    backView.layer.masksToBounds = YES;
    imageView.layer.cornerRadius = 140;
    imageView.layer.masksToBounds = YES;
    [self.view addSubview:backView];
    [self.view addSubview:imageView];
}
#pragma mark - pageConrol
- (void)pageControl {
    UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 0, 40, 20)];
    pageControl.center = CGPointMake(SCREEN_WIDTH / 2, 520);
    pageControl.numberOfPages = 3;
    pageControl.currentPage = 1;
    pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
    pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
    [self.view addSubview:pageControl];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    label.text = @"曲: 周杰伦";
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor grayColor];
    label.center = CGPointMake(SCREEN_WIDTH / 2, 490);
    [self.view addSubview:label];
}
#pragma mark - slider
- (void)slider {
    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - 300) / 2, 540, 300, 10)];
    [slider setMaximumTrackImage:[UIImage imageNamed:@"player_slider_playback_right"] forState:UIControlStateNormal];
    [slider setMinimumTrackImage:[UIImage imageNamed:@"player_slider_playback_left"] forState:UIControlStateNormal];
    [slider setThumbImage:[UIImage imageNamed:@"player_slider_playback_thumb"] forState:UIControlStateNormal];
    [self.view addSubview:slider];
}
#pragma mark - playButton
- (void)playButton {
    GX_Button *leftButton = [GX_Button buttonWithType:UIButtonTypeSystem];
    leftButton.frame = CGRectMake(SCREEN_WIDTH / 2 - 150, 570, 90, 90);
    [leftButton setImage:[[UIImage imageNamed:@"hp_player_btn_pre_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.view addSubview:leftButton];
    GX_Button *midButton = [GX_Button buttonWithType:UIButtonTypeSystem];
    midButton.frame = CGRectMake(SCREEN_WIDTH / 2 - 50, 565, 100, 100);
    [midButton setImage:[[UIImage imageNamed:@"player_btn_pause_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.view addSubview:midButton];
    GX_Button *rightButton = [GX_Button buttonWithType:UIButtonTypeSystem];
    rightButton.frame = CGRectMake(SCREEN_WIDTH / 2 + 60, 570, 90, 90);
    [rightButton setImage:[[UIImage imageNamed:@"hp_player_btn_next_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.view addSubview:rightButton];
    GX_Button *vedioButton = [GX_Button buttonWithType:UIButtonTypeSystem];
    vedioButton.frame = CGRectMake(SCREEN_WIDTH / 2 + 150, 590, 50, 50);
    [vedioButton setImage:[[UIImage imageNamed:@"player_btn_airplayon_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.view addSubview:vedioButton];
}
#pragma mark - timeLabel
- (void)timeLabel {
    //创建左边的label
    UILabel *leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 535, 50, 20)];
    [self.view addSubview:leftLabel];
    leftLabel.textColor = [UIColor whiteColor];
    leftLabel.text = @"00:13";
    //创建右边的label
    UILabel *rightLabel = [[UILabel alloc] initWithFrame:CGRectMake(360, 535, 50, 20)];
    [self.view addSubview:rightLabel];
    rightLabel.textColor = [UIColor whiteColor];
    rightLabel.text = @"03:13";
}
- (void)bottomItem {
    for (int i = 0; i < 5; i++) {
        GX_Button *button = [GX_Button buttonWithType:UIButtonTypeSystem];
        button.frame = CGRectMake(20 + i * (SCREEN_WIDTH - 40) / 5, 670, (SCREEN_WIDTH - 40) / 5, 70);
        [button setImage:[[UIImage imageNamed:@"0"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        [self.view addSubview:button];
    }
}
#pragma mark - AVAudioPlayer
- (void)avAudioPlayer {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"歌曲" ofType:@"MP3"];
    NSURL *url = [NSURL fileURLWithPath:path];
    self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
    // 负数表示无限循环播放, 0表示播放一次, 以此类推
    _player.numberOfLoops = 1;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
